package com.fit.WatchShop.pages;

import java.util.LinkedList;

import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SessionState;
import org.apache.tapestry5.annotations.SetupRender;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.fit.WatchShop.beans.BuyerBean;
import com.fit.WatchShop.interfaces.Buy;
import com.fit.WatchShop.interfaces.Buyer;
import com.fit.WatchShop.interfaces.User;
import com.fit.WatchShop.service.Buyers;

public class EntryBuyer {

	@Property
	@Persist
	private Buyer buyer;
	
	@Inject
	private Buyers buyers;
	
	@SetupRender
	public void createObject() {
		buyer = new BuyerBean();
		buyer.setBuy(new LinkedList<Buy>());
	}
	
	void onSuccess() {
		buyers.save(buyer);
	}
	@SessionState
	private User user;

	private boolean userExists;
	
	public User getUser() {
		return user;
	}
	
	Object onActivate() {
		if (!userExists) return Login.class;
		return null;
	}
}
